package com.dzgs.zw;

import com.dzgs.zw.model.Cfg;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.AnsiSqlDialect;
import com.jfinal.plugin.activerecord.tx.TxByRegex;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

public class CfgZw extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		loadPropertyFile("config.conf");
		me.setDevMode(getPropertyToBoolean("devMode", true));
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", CtlZw.class);
		me.add("/zw", CtlZw.class);

	}

	@Override
	public void configPlugin(Plugins me) {
		C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("url"),
				getProperty("user"), getProperty("password"),
				getProperty("driver"));
		me.add(c3p0Plugin);
		// c3p0Plugin.start();
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		arp.setDialect(new AnsiSqlDialect());
		me.add(arp);
		Cfg.DWID=getProperty("SSDWID");
	}

	@Override
	public void configInterceptor(Interceptors me) {
		me.add(new TxByRegex(".*Save.*"));
		me.add(new TxByRegex(".*Update.*"));
		me.add(new TxByRegex(".*Del.*"));
	}

	@Override
	public void configHandler(Handlers me) {
		me.add(new ContextPathHandler("baseUrl"));
	}

}
